package com.example.springboot_demo01.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot_demo01.entity.Student;
import com.example.springboot_demo01.query.StudentQuery;
import com.example.springboot_demo01.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/student")
@Api(tags = "学生信息管理接口")
public class StudentController {

    @Resource
    StudentService studentService;

    @ApiOperation("获得学生记录")
    @GetMapping
    public List<Student> getAll(StudentQuery query){
        List<Student> dataList =
                studentService.getAll(query);
        return dataList;

    }

    @ApiOperation("获得学生记录--带分页")
    @GetMapping("/getPage")
    public Page<Student> getPage(StudentQuery query){
        return studentService.getPage(query);
    }

    @ApiOperation("根据id获得某个学生信息")
    @GetMapping("/{id}")
    public Student getById(@PathVariable("id") int id){
        return studentService.getById(id);
    }

    @ApiOperation("根据id删除某个学生")
    @DeleteMapping("/{id}")
    public int delete(@PathVariable("id") int id){
        return studentService.delete(id);
    }

    @ApiOperation("增加学生")
    @PostMapping
    public int add(@RequestBody Student onj){
        return 1;
    }

    @ApiOperation("修改学生")
    @PutMapping
    public int edit(@RequestBody Student obj){
        return 1;
    }
}
